package com.smartlink.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.smartlink.app.R;

/**
 * 室外环境适配器
 * Created by Administrator on 2016/7/7.
 */
public class GridItemAdapter extends BaseAdapter {
    private String[] titles;
    private String[] vlaues;
    private int[] images;
    private Context ctx;

    public GridItemAdapter(Context ctx, String[] titles, String[] vlaues, int[] images) {
        this.ctx = ctx;
        this.titles = titles;
        this.vlaues = vlaues;
        this.images = images;
    }

    @Override
    public int getCount() {
        return vlaues.length;
    }

    @Override
    public Object getItem(int position) {
        return vlaues[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(ctx).inflate(R.layout.grid_item_out_door, null);
            holder = new ViewHolder();
            holder.iv_grid_out_logo = (ImageView) convertView.findViewById(R.id.iv_grid_out_logo);
            holder.tv_grid_out_value = (TextView) convertView.findViewById(R.id.tv_grid_out_value);
            holder.tv_grid_out_title = (TextView) convertView.findViewById(R.id.tv_grid_out_title);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv_grid_out_title.setText(titles[position]);
        holder.tv_grid_out_value.setText(vlaues[position]);
        holder.iv_grid_out_logo.setImageResource(images[position]);

        return convertView;
    }

    public static class ViewHolder {
        TextView tv_grid_out_title, tv_grid_out_value;
        ImageView iv_grid_out_logo;
    }
}
